<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="vue.js"></script>
</head>
<body>
    <div id="app">
        <my-parent></my-parent>
    </div>
    <template id="son">
        <div>
        </div>
    </template>
    
    <template id="father">
      
        <div>
            {{ message }} {{ years }} {{ sex }} 
            <button @click="getData">拿到子组件的数据</button>
            <my-son ref="my"></my-son>
            <my-son ref="lmx"></my-son>
            <my-son ref="cyj"></my-son>            
        </div>
    </template>
    
    <script>
    const son = {
        template: '#son',
        data() {
            return {
                msg: '我是子组件的消息,你看看能拿到么',
                age: 24,
                sex: '男'
            }
        }
    }

    const father = {
        template: '#father',
        data(){
            return {
                message: '',
                years: 0,
                sex: ''
            }
        },
        components: {
            'mySon': son
        },
        methods: {
            getData(){
                console.log(this.$refs.my.msg)
                this.message = this.$refs.cyj.msg;
                this.years = this.$refs.cyj.age;
                this.sex = this.$refs.lmx.sex;
            }
        }
    }
    new Vue({
        el: '#app',
        components: {
            'myParent': father 
        }
    })
    </script>
</body>
</html>